var BaseUrl = "http://localhost:8181";
var Ajax= function (checkLogin,url,method,data,header) {
    var token = localStorage.getItem("token");
    if (checkLogin && token){
        if (header){header['token'] = token}
        else header = {token:token}
    }else{
        if (checkLogin) location.href = '/template/login.html';
    }
    var deferred = $.Deferred();
    var ss = $.ajax({
        type: method,
        url:BaseUrl+ url,
        headers: header,
        data:data,
        contentType:'application/json; charset=UTF-8',
        success: function (data) {
            deferred.resolve(data);
        },
        error: function (err) {
            deferred.reject(err);
        }
    });
    return $.when(ss);
};
var Comm = function () {
    return {
        logout:function () {
            localStorage.removeItem('token');
        }
    };
};
